<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>点击变心案例</title>
    <script src="./vue.js"></script>
    <style>
        .active {
            background-color: pink;
        }
    </style>
</head>

<body>
    <div id="box">
        <ul>
            <li v-for="(item, index) in dataList" :key="index" @click="handleClick(index)"
                :class="current===index?'active':''">{{item}}</li>
        </ul>
    </div>
    <script>
        const obj = {
            data() {
                return {
                    dataList: [11, 22, 33, 44, 55, 66],
                    current: -1, //当前点击的索引值
                }
            },
            methods: {
                handleClick(index) {
                    this.current = index
                }
            }
        }
        Vue.createApp(obj).mount('#box');
    </script>
</body>

</html>